import { defineConfig } from "vite";
const path = require("path");
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";
import AutoImport from "unplugin-auto-import/vite";
import { visualizer } from "rollup-plugin-visualizer";
// const BASE_API = import.meta.env.VITE_APP_BASE_API

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // visualizer({  //    build后的视图
    //   open: true,
    //   gzipSize: true,
    //   brotliSize: true
    // }),
    Components({
      resolvers: [VantResolver()]
    }),
    AutoImport({
      imports: [
        "vue",
        "vue-router",
        {
          "@/utils/command/index.js": [
            // default imports
            ["default", "command"] // import { default as command } from '@/utils/command/index.js',
          ]
        }
      ] // 自动导入vue和vue-router相关函数
    })
  ],
  server: {
    host: "0.0.0.0",
    port: 81,
    open: true
  },
  base: "./",
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      components: path.resolve(__dirname, "src/components"),
      views: path.resolve(__dirname, "src/views"),
      utils: path.resolve(__dirname, "src/utils")
    }
  },
  build: {
    lib: {
      entry: 'src/components/MyCount/index.ts', // 将打包入口更改为src/MyCount/index.ts，就可以单独将web组件打包出去
      formats: ['umd'],
      name: 'myCount.js',
      fileName: () => 'myCount.js' // 打包js文件名
    }
  }
});
